import { createStore, useStore as baseUseStore, Store } from 'vuex'
import { InjectionKey } from 'vue'

import { IApp, app } from '@/store/modules/app'
import { IUser, user } from '@/store/modules/user'
import { IPermission, permission } from '@/store/modules/permission'

interface allType {
  user: IUser;
  app: IApp;
  permission: IPermission;
}

// 定义 injection key
export const key: InjectionKey<Store<allType>> = Symbol('store')

// 创建一个新的 store 实例
export const store = createStore<allType>({
  modules: {
    app,
    user,
    permission
  }
})

export function useStore () {
  return baseUseStore(key)
}
